import { userAccountLogin } from '@/api/user'
// 用户状态
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),
  mutations: {
    updateId (state, payload) {
      state.profile.id = payload
    },
    setUser (state, form) {
      state.profile = form
    },
    delUser (state) {
      state.profile = {}
    }
  },
  actions: {
    async getUserInfo ({ commit }, form) {
      const { result } = await userAccountLogin(form)
      console.log(result)
      commit('setUser', result)
    },
    logout ({ commit }) {
      commit('delUser')
      commit('cart/setList', [], { root: true })
    }
  }
}
